const { TreeItem, TreeItemCollapsibleState } = require("vscode");

class MyTreeItem extends TreeItem {
  /**
   * @param {string | import("vscode").TreeItemLabel} label
   * @param {TreeItemCollapsibleState} collapsibleState
   * @param {string} command
   * @param {string[]} commandArgs
   */
  constructor(label, collapsibleState, command, commandArgs) {
    super(label, collapsibleState);
    this.contextValue = "customNode"; // 自定义 contextValue，用于区分不同的节点
    this.command = {
      command: command,
      title: "Click to Execute Command",
      arguments: commandArgs,
    };
  }
}

class TreeViewProvider {
  /**
   * @param {any} element
   */
  getTreeItem(element) {
    return element;
  }

  /**
   * @param {{ label: string; }} element
   */
  getChildren(element) {
    let arr = [];
    // if (element === undefined) {
    //   let item1 = new MyTreeItem(
    //     "Father",
    //     TreeItemCollapsibleState.Collapsed,
    //     "itemClick",
    //     ["arg1"]
    //   );
    //   item1.description = "age 28";
    //   arr.push(item1);
    //   let item2 = new MyTreeItem(
    //     "Uncle",
    //     TreeItemCollapsibleState.None,
    //     "aplc.start",
    //     ["arg1"]
    //   );
    //   item2.description = "age 26";
    //   arr.push(item2);
    //   return arr;
    // } else {
    //   if (element.label === "Father") {
    //     let item1 = new MyTreeItem(
    //       "Son",
    //       TreeItemCollapsibleState.None,
    //       "aplc.start",
    //       ["arg1"]
    //     );
    //     item1.description = "age 3";
    //     arr.push(item1);
    //     return arr;
    //   } else {
    //     return null;
    //   }
    // }
    let item2 = new MyTreeItem(
      "AntdProLowCode",
      TreeItemCollapsibleState.None,
      "aplc.start",
      ["arg1"]
    );
    arr.push(item2);
    return arr;
  }

  getParent() {
    throw new Error("Method not implemented.");
  }

  resolveTreeItem() {
    throw new Error("Method not implemented.");
  }
}

module.exports = TreeViewProvider;
